/*
 * Common.h
 *
 *  Created on: Oct 11, 2023
 *      Author: yglc
 */

#ifndef COMMON_H_
#define COMMON_H_

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <pthread.h>

extern volatile int      g_IsRunning;

#define VERSION      0
#define CHANNEL_AD1  7
#define CHANNEL_AD2  8
#define CHANNEL_AD3  9
#define CHANNEL_AD4  10
#define CHANNEL_AD5  11
#define CHANNEL_AD6  12
#define CHANNEL_AD7  13
#define CHANNEL_AD8  14

//AD7134
#define  AD7134_ENABLE   1
#define  AD7134_W        2
#define  AD7134_R        3
#define  AD7134_CS       4
#define  AD7134_RESET    5
#define  AD7134_R_VALUE  6

//AD5755
#define  AD5755_ENABLE  15
#define  AD5755_RW      16
#define  AD5755_VALUE   17
#define  AD5755_RESET   18

//TMC5130
#define TMC5130_ENABLE  19
#define TMC5130_RW      20
#define TMC5130_W_VALUE 21
#define TMC5130_MODE    22
#define TMC5130_SPEED   23
#define TMC5130_ANGLE   24
#define TMC5130_MODE_EN 25
#define TMC5130_STOP    26
#define TMC5130_XUANZHUAN  27

//pwm
#define PWM              28

//EEPROM
#define EEPROM_EN        29
#define EEPROM_RW        30
#define EEPROM_VALUE     31

//BISS
#define BISS_EN          32
#define BISS_VALUE       33

//待测信号
#define SIGNAL_0         37
#define SIGNAL_1         38
#define SIGNAL_2         39
#define SIGNAL_3         40

//EC11
#define EC11_NUM         41
#define EC11_KEY         42



#pragma pack(1)

typedef struct
{
    unsigned char frame_head[2];
    unsigned char device_id;
    unsigned char cmd;
    uint32_t addr;
    uint32_t value;
    unsigned char frame_end[2];

} NET_CMD;

typedef struct
{
    unsigned char frame_head[2];
    unsigned char device_id;
    unsigned char cmd;
    uint32_t addr;
    uint32_t value;
    uint32_t count;
    char buf[4096];
    unsigned char frame_end[2];

} NET_DATA;

#pragma pack()



class CCommon {
public:
	CCommon();
	virtual ~CCommon();
};

#endif /* COMMON_H_ */
